package org.nf.web.config;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.setting.yaml.YamlUtil;

/**
 * @author wangl
 * @date 2023/5/16
 */
public class Configure {

    public final static String APPLICATION_YML = "application.yml";
    /**
     * web服务器配置
     */
    private ServerConfig server = new ServerConfig();
    /**
     * mvc配置
     */
    private MvcConfig mvc = new MvcConfig();

    public MvcConfig getMvc() {
        return mvc;
    }

    public void setMvc(MvcConfig mvc) {
        this.mvc = mvc;
    }

    public ServerConfig getServer() {
        return server;
    }

    public void setServer(ServerConfig server) {
        this.server = server;
    }

    public static Configure init() {
        String configFilePath = ClassUtil.getClassPath() + Configure.APPLICATION_YML;
        Configure config;
        if(FileUtil.exist(configFilePath)) {
            config = YamlUtil.loadByPath(Configure.APPLICATION_YML, Configure.class);
            if(config == null) {
                config = new Configure();
            }
        } else {
            config = new Configure();
        }
        return config;
    }
}